<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use think\Response;

Route::miss(function () {
    $appRequest = request()->pathinfo();
    if ($appRequest === null) {
        $appName = '';
    } else {
        $appRequest = str_replace('//', '/', $appRequest);
        $appName = explode('/', $appRequest)[0] ?? '';
    }

    switch (strtolower($appName)) {
        case 'adminapi':
        default:
        // 未注册路由默认显示文档页
        $docFilePath = app()->getRootPath() . 'public' . DS . 'docs' . DS . 'index.html';

        if (file_exists($docFilePath)) {
            // 直接返回文件内容，设置Content-Type为text/html
            return Response::create(file_get_contents($docFilePath), 'html');
        }

        return Response::create('文件不存在', 'html', 404);
    }
});